home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / xtclock2.zip / GETCLOCK.C < prev    next >
C/C++ Source or Header  |  1991-07-30  |  2KB  |  94 lines

  1.  
  2. /*    Program      GETCLOCK                    */
  3. /*    Version         2.0                        */
  4. /*    Compiler     MIX Power C                     */
  5. /*    Author         Gerald M. Vrooman                  */
  6. /*      Date         07/30/91                     */
  7.  
  8. /*     GETCLOCK can be used with an XT clock card to initialize DOS    */
  9. /*         time and date when  booting up. The Multi I/O  card that  this  */
  10. /*    routine  was designed for uses the following ports:         */
  11.  
  12. /*        &h242 - Second                        */
  13. /*        &h243 - Minute                        */
  14. /*        &h244 - Hour                        */
  15. /*        &h246 - Day                        */
  16. /*        &h247 - Month                        */
  17. /*        &h249 - year                        */
  18.  
  19. /*     If necessary this program can be modified for cards with        */
  20. /*     different port addresses merely by changing the arguments    */
  21. /*     used with inportb() .                        */
  22.  
  23.  
  24.     #include <stdio.h>
  25.     #include <dos.h>
  26.     #include <stdlib.h>
  27.  
  28.     main(int argc,char *argv[])
  29.  
  30.     {
  31.     int year,month,day,hour,minute,second;
  32.     char buffer[5];
  33.  
  34.     struct {
  35.         unsigned char ti_min;
  36.         unsigned char ti_hour;
  37.         unsigned char ti_hund;
  38.         unsigned char ti_sec;
  39.     } timebuf;
  40.  
  41.     struct {
  42.         int da_year;
  43.         char da_day;
  44.         char da_mon;
  45.     } datebuf;
  46.  
  47.  
  48.  
  49.      printf("\nGETCLOCK  Written 1991 by Gerald M. Vrooman\n\n");
  50.  
  51.          year = bcdint(inportb(0x249)); 
  52.      if (year >= 80)  
  53.            datebuf.da_year = year + 1900;  
  54.      else
  55.        datebuf.da_year = year + 2000;      
  56.  
  57.          month = bcdint(inportb(0x247));
  58.          datebuf.da_mon = month;
  59.  
  60.          day = bcdint(inportb(0x246));
  61.          datebuf.da_day = day;
  62.  
  63.          setdate(&datebuf);
  64.  
  65.  
  66.          hour = bcdint(inportb(0x244));
  67.          timebuf.ti_hour = hour;
  68.  
  69.          minute = bcdint(inportb(0x243));
  70.          timebuf.ti_min = minute;
  71.  
  72.          second = bcdint(inportb(0x242));
  73.          timebuf.ti_sec = second;
  74.  
  75.          timebuf.ti_hund = 0;
  76.  
  77.          settime(&timebuf);
  78.  
  79.     }
  80.  
  81.  
  82.     /* bcdint converts binary coded decimal byte to integer */
  83.  
  84.     bcdint(bcd)
  85.     int bcd;
  86.     {
  87.          int tens,ones;
  88.  
  89.          tens = bcd / 16;
  90.          ones = bcd % 16;
  91.          return(tens * 10 + ones);
  92.     }
  93.  
  94.